import time
from multiprocessing import Process


class EatProcess(Process):
    """ 写一个自定义的类，继承Process """

    def __init__(self, name):
        super().__init__()  # 注意：必须要有这句话
        self.name = name

    def run(self):  # 必须要重写Process的run函数
        for i in range(6):
            print(f'进程{self.name}:正在吃饭。。。')
            time.sleep(0.3)


class WorkProcess(Process):
    """ 写一个自定义的类，继承Process """

    def __init__(self, name):
        super().__init__()  # 注意：必须要有这句话
        self.name = name

    def run(self):  # 必须要重写Process的run函数
        for i in range(6):
            print(f'进程{self.name}:正在做作业。。。')
            time.sleep(0.3)


if __name__ == '__main__':
    p1 = EatProcess('process-01')
    p2 = WorkProcess('process-02')

    p1.start()
    # 启动的子进程才可以调用join函数：主进程阻塞，一直到当前的子进程执行完成
    p1.join()
    p2.start()
